-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Fix: deduplicated "is_prime" functions #5488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: deduplicated "is_prime" functions #5488
Conversation
FAILED project_euler/problem_015/sol1.py::project_euler.problem_015.sol1.solution but I didn't even change that file :c |
|
def prime_check(number: int) -> bool: | ||
"""Checks to see if a number is a prime. | ||
"""Checks to see if a number is a prime in O(sqrt(n)). | ||
|
||
A number is prime if it has exactly two factors: 1 and itself. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a few tests to this function (although we have tests down there, we can still add a few doctests).
@@ -8,7 +8,6 @@ | |||
|
|||
Overview: | |||
|
|||
isPrime(number) | |||
sieveEr(N) | |||
getPrimeNumbers(N) | |||
primeFactorization(number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change these signatures too, e.g. sieve_of_eratosthenes
""" | ||
Returns boolean representing primality of given number num. | ||
|
||
>>> isprime(2) | ||
True | ||
>>> isprime(3) | ||
True | ||
>>> isprime(27) | ||
False | ||
>>> isprime(2999) | ||
True | ||
>>> isprime(0) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Parameter num must be greater than or equal to two. | ||
>>> isprime(1) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Parameter num must be greater than or equal to two. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just copy-paste these to the prime check
>>> is_prime(2) | ||
True | ||
>>> is_prime(15) | ||
False | ||
>>> is_prime(29) | ||
True | ||
>>> is_prime(0) | ||
False | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be copy-pasted
>>> isprime(2) | ||
True | ||
>>> isprime(15) | ||
False | ||
>>> isprime(29) | ||
True | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be copy-pasted
>>> is_prime(2) | ||
True | ||
>>> is_prime(3) | ||
True | ||
>>> is_prime(27) | ||
False | ||
>>> is_prime(2999) | ||
True | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be copy-pasted
>>> is_prime(2) | ||
True | ||
>>> is_prime(3) | ||
True | ||
>>> is_prime(27) | ||
False | ||
>>> is_prime(2999) | ||
True | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be copy-pasted
>>> is_prime(67483) | ||
False | ||
>>> is_prime(563) | ||
True | ||
>>> is_prime(87) | ||
False | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be copy-pasted
It's probably |
In Python 3.10
so it's causing errors: https://github.com/TheAlgorithms/Python/runs/3958162685?check_suite_focus=true#step:3:5 |
Please see and wait for #5496. |
I will close this PR for now, wait for #5496 and make separate PRs for the changes discussed. Thanks for the feedback! |
Unified all functions that check if number is prime to maths/check_prime.py check_prime function, that checks primality in O(sqrt(n)).
Functions left unchanged:
Fixes: #5434
Checklist:
Fixes: #{$ISSUE_NO}
.